package solution;
import java.util.TreeMap;
import java.util.Scanner;

/**
 * Created by wangxingsheng on 2022/6/20.
 * 列表合并
 */
public class KVMerge {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        TreeMap<Integer,Integer> map = new TreeMap<>();
        for(int i=0; i < count;i++){
            int index = in.nextInt();
            int value = in.nextInt();
            Integer last = map.getOrDefault(index, 0);
            map.put(index, value + last);
        }
        for(Integer key : map.keySet()){
            System.out.println(key + " " + map.get(key));
        }
    }
}
